package com.itheima.controller;

import com.itheima.common.CommonResult;
import com.itheima.common.PageInfo;
import com.itheima.dto.OrderDto;
import com.itheima.service.OrderService;
import com.itheima.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author YangJiaHao
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public CommonResult submit(@RequestBody OrderDto orderDto){
        orderService.add(orderDto);
        return CommonResult.success("下单成功");
    }

    @GetMapping("/userPage")
    public CommonResult getOrderPage(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10")Integer pageSize){
        PageInfo<OrderVo> pageInfo = orderService.getOrderPage(page,pageSize);
        return CommonResult.success(pageInfo);
    }
}
